/*
 * SimpleModal OSX Style Modal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2010 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: osx.js 238 2010-03-11 05:56:57Z emartin24 $
 */

jQuery(function($){
	var OSX = {
		container: null,
		init: function () {
			$("input.osx, a.osx").click(function (e) {
				e.preventDefault();	

				$("#osx-modal-content").modal({
					overlayId: 'osx-overlay',
					containerId: 'osx-container',
					closeHTML: null,
					minHeight: 80,
					opacity: 65, 
					position: ['15%', ],
					overlayClose: false, //true,
					onOpen: OSX.open,
					onClose: OSX.close
				});
			});
		},
		open: function (d) {
			var self = this;
			self.container = d.container[0];
			d.overlay.fadeIn('slow', function () {
				$("#osx-modal-content", self.container).show();
				var title = $("#osx-modal-title", self.container);
				title.show();
				d.container.slideDown('slow', function () {
					setTimeout(function () {
						var h = $("#osx-modal-data", self.container).height()
							+ title.height() + 20; // padding
						d.container.animate(
							{height: h}, 
							200,
							function () {
								$("div.close", self.container).show();
								$("#osx-modal-data", self.container).show();
							}
						);
					}, 300);
				});
			})
		},
		close: function (d) {
			var self = this; // this = SimpleModal object
			d.container.animate(
				{top:"-" + (d.container.height() + 20)},
				500,
				function () {
					self.close(); // or $.modal.close();
				}
			);
		}
	};

	OSX.init();   
});


/*
 * SimpleModal Confirm Modal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2010 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: confirm.js 238 2010-03-11 05:56:57Z emartin24 $
 *
 */

jQuery(function ($) {
	$('#confirm-dialog1 input.confirm1, #confirm-dialog1 a.confirm1').click(function (e) {
		e.preventDefault();

		// example of calling the confirm function
		// you must use a callback function to perform the "yes" action
		confirm(function () {
			window.location.href = '';
		});
	});
}); 

function confirm(title, message, display, callback) {
	$('#confirm').modal({
		closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["20%",],
		overlayId: 'confirm-overlay',
		containerId: 'confirm-container', 
		onShow: function (dialog) {
			$('.header span', dialog.data[0]).html(title);
			$('.message', dialog.data[0]).append(message);
            $('#confirm-overlay').css('z-index', '10010');
            $('#confirm-container').css('z-index', '10011');        
            
            if(display == 'notify'){ 
				$('.continue', dialog.data[0]).show();
				$('.yes', dialog.data[0]).hide();
				$('.yes1', dialog.data[0]).hide();
				$('.no', dialog.data[0]).hide();	
				$('#confirm .buttons').css('float', 'none');
				$('.continue', dialog.data[0]).css('float', 'none'); 
				  
				var w = $('#confirm').width() / 2 - $('.continue', dialog.data[0]).width() / 2 - 10;
				$('.continue', dialog.data[0]).css('margin-left', w);
            }
            else if (display == 'yesno') {
				$('.continue', dialog.data[0]).hide();
				$('.yes', dialog.data[0]).hide();
				$('.yes1', dialog.data[0]).show();
				$('.no', dialog.data[0]).show();	       
				$('#confirm .buttons').css('float', 'right');
			}
			else { 
				$('.continue', dialog.data[0]).hide();
				$('.yes1', dialog.data[0]).hide();
				$('.yes', dialog.data[0]).show();
				$('.no', dialog.data[0]).show();
				$('#confirm .buttons').css('float', 'right');
			}
            
            $('.continue', dialog.data[0]).click(function () {
				$.modal.close(); 
			});		
				
			// if the user clicks "yes"
			$('.yes', dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
					
					$('.continue', dialog.data[0]).show();
					$('.yes', dialog.data[0]).hide();
					$('.yes1', dialog.data[0]).hide();
					$('.no', dialog.data[0]).hide();	
					
					$('#confirm .buttons').css('float', 'none');
					$('.continue', dialog.data[0]).css('float', 'none');
					var w = $('#confirm').width() / 2 - $('.continue', dialog.data[0]).width() / 2 - 10;
					$('.continue', dialog.data[0]).css('margin-left', w);
				}
				// close the dialog
				//$.modal.close();
			});
			
			// if the user clicks "yes1"
			$('.yes1', dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
					$.modal.close();
				}
			});

            setTimeout(
                function () {
                    $.modal.close();
					/*
					if(jQuery('#TB_closeWindowButton')length > 0){
						jQuery('#TB_closeWindowButton').trigger('click');
					}
					*/
                },
                7000
            );
		}
	});
}

function filterByAttribute(title, row, callback) {
    $('#filter_by_attribute' + row).modal({
        closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
        position: ["5%",],
        overlayId: 'filter_by_attribute-overlay',
        containerId: 'filter_by_attribute-container',   
        minHeight: 450,
        minWidth: 550, //670,         
        onShow: function (dialog) {           
            $('.header span', dialog.data[0]).html(title); 
            $('.message', dialog.data[0]).css('height', 355);                          
            
            $('.cancel', dialog.data[0]).click(function () {
                $.modal.close(); 
            });  
            $('.continue', dialog.data[0]).click(function () {
                if ($.isFunction(callback)) {
                    callback.apply();                    
                }
                
                //$.modal.close();
            });       
        }
    });
}

function sendQuestionForm(text) {
    $('#send_question_form').modal({
        closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
        position: ["5%",],
        overlayId: 'send_question_form-overlay',
        containerId: 'send_question_form-container',                  
        onShow: function (dialog) {                                                 
            $('.continue', dialog.data[0]).click(function () {
                $.modal.close(); 
            });   
                   
            $('.product_link', dialog.data[0]).val(text);
        }
    });
}